package com.changgou.controller;

import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import com.changgou.goods.pojo.Para;
import com.changgou.service.ParaService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 参数控制层
 *
 * @author gaofeng
 * @date 2025/4/20 10:51
 */
@Api(value = "ParaController")
@RestController
@RequestMapping("/param")
@CrossOrigin
public class ParaController {
    @Resource
    private ParaService paraService;

    /**
     * Para分页条件搜索实现
     *
     * @param para 查询条件
     * @param page 当前页
     * @param size 每页显示条数
     * @return com.changgou.entity.Result<com.github.pagehelper.PageInfo < com.changgou.goods.pojo.Para>>
     */
    @ApiOperation(value = "Para条件分页查询", notes = "分页条件查询Para方法详情", tags = {"ParaController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @PostMapping(value = "/search/{page}/{size}")
    public Result<PageInfo> findPage(@RequestBody(required = false) @ApiParam(name = "Para对象", value = "传入JSON数据") Para para, @PathVariable int page, @PathVariable int size) {
        PageInfo<Para> pageInfo = paraService.findPage(para, page, size);
        return new Result(true, StatusCode.OK, "查询成功", pageInfo);
    }

    /**
     * Para分页搜索实现
     *
     * @param page 当前页
     * @param size 每页显示多少条
     * @return com.changgou.entity.Result<com.github.pagehelper.PageInfo < com.changgou.goods.pojo.Para>>
     */
    @ApiOperation(value = "Para分页查询", notes = "分页查询Para方法详情", tags = {"ParaController"})
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "page", value = "当前页", required = true, dataType = "Integer"),
            @ApiImplicitParam(paramType = "path", name = "size", value = "每页显示条数", required = true, dataType = "Integer")
    })
    @GetMapping(value = "/search/{page}/{size}")
    public Result<PageInfo> findPage(@PathVariable int page, @PathVariable int size) {
        PageInfo<Para> pageInfo = paraService.findPage(page, size);
        return new Result<>(true, StatusCode.OK, "查询成功", pageInfo);
    }

    /**
     * 多条件搜索品牌数据
     *
     * @param para 查询条件
     * @return com.changgou.entity.Result<java.util.List < com.changgou.goods.pojo.Para>>
     */
    @ApiOperation(value = "Para条件查询", notes = "条件查询Para方法详情", tags = {"ParaController"})
    @PostMapping(value = "/search")
    public Result<List<Para>> findList(@RequestBody(required = false) @ApiParam(name = "Para对象", value = "传入JSON数据") Para para) {
        List<Para> list = paraService.findList(para);
        return new Result<>(true, StatusCode.OK, "查询成功", list);
    }

    /**
     * 根据ID删除品牌数据
     *
     * @param id 主键
     * @return com.changgou.entity.Result
     */
    @ApiOperation(value = "Para根据ID删除", notes = "根据ID删除Para方法详情", tags = {"ParaController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Integer")
    @DeleteMapping(value = "/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        paraService.delete(id);
        return new Result(true, StatusCode.OK, "删除成功");
    }

    /**
     * 修改Para数据
     *
     * @param para 参数信息
     * @param id   主键
     * @return com.changgou.entity.Result
     */
    @ApiOperation(value = "Para根据ID修改", notes = "根据ID修改Para方法详情", tags = {"ParaController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Integer")
    @PutMapping(value = "/update/{id}")
    public Result update(@RequestBody @ApiParam(name = "Para对象", value = "传入JSON数据") Para para, @PathVariable Integer id) {
        para.setId(id);
        paraService.update(para);
        return new Result(true, StatusCode.OK, "修改成功");
    }

    /**
     * 新增Para数据
     *
     * @param para 参数信息
     * @return com.changgou.entity.Result
     */
    @ApiOperation(value = "Para添加", notes = "添加Para方法详情", tags = {"ParaController"})
    @PostMapping(value = "/add")
    public Result add(@RequestBody @ApiParam(name = "Para对象", value = "传入JSON数据", required = true) Para para) {
        paraService.add(para);
        return new Result(true, StatusCode.OK, "添加成功");
    }

    /**
     * 根据ID查询Para数据
     *
     * @param id 主键
     * @return com.changgou.entity.Result<com.changgou.goods.pojo.Para>
     */
    @ApiOperation(value = "Para根据ID查询", notes = "根据ID查询Para方法详情", tags = {"ParaController"})
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", required = true, dataType = "Integer")
    @GetMapping("/findById/{id}")
    public Result<Para> findById(@PathVariable Integer id) {
        Para para = paraService.findById(id);
        return new Result<>(true, StatusCode.OK, "查询成功", para);
    }

    /**
     * 查询Para全部数据
     *
     * @return 参数集合
     */
    @ApiOperation(value = "查询所有Para", notes = "查询所Para有方法详情", tags = {"ParaController"})
    @GetMapping(value = "/findAll")
    public Result<List<Para>> findAll() {
        List<Para> list = paraService.findAll();
        return new Result<>(true, StatusCode.OK, "查询成功", list);
    }

    /**
     * 根据categoryId查询参数信息
     *
     * @param categoryId 分类id
     * @return com.changgou.entity.Result<java.util.List < com.changgou.goods.pojo.Para>>
     */
    @ApiOperation(value = "根据categoryId查询参数信息", notes = "根据categoryId查询参数信息", tags = {"ParaController"})
    @GetMapping(value = "/findByCategoryId/{categoryId}")
    public Result<List<Para>> findByCategoryId(@PathVariable(value = "categoryId") Integer categoryId) {
        return new Result<>(true, StatusCode.OK, "查询参数集合成功", paraService.findByCategoryId(categoryId));
    }
}
